﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Reflection;
using ObjectTransposeApi.Handler.Expand;
using ObjectTransposeApi.Handler.Property;

namespace ObjectTransposeApi.Helper
{
    /// <summary/>
    internal static class ChainHelper
    {
        /// <summary/>
        internal static AbstractExpandHandler FetchExpandHandlers()
        {
            NullExpandHandler nullExpandHandler = new NullExpandHandler();
            StringExpandHandler stringExpandHandler = new StringExpandHandler();
            HashTableExpandHandler hashTableExpandHandler = new HashTableExpandHandler();
            DictionaryExpandHandler dictionaryExpandHandler = new DictionaryExpandHandler();
            EnumerableExpandHandler enumerableExpandHandler = new EnumerableExpandHandler();
            EnumeratorExpandHandler enumeratorExpandHandler = new EnumeratorExpandHandler();
            DefaultExpandHandler defaultExpandHandler = new DefaultExpandHandler();

            // create the chain
            nullExpandHandler.Successor = stringExpandHandler;
            stringExpandHandler.Successor = hashTableExpandHandler;
            hashTableExpandHandler.Successor = dictionaryExpandHandler;
            dictionaryExpandHandler.Successor = enumerableExpandHandler;
            enumerableExpandHandler.Successor = enumeratorExpandHandler;
            enumeratorExpandHandler.Successor = defaultExpandHandler;
        
            // return the top
            return nullExpandHandler;
        }

        /// <summary/>
        internal static AbstractPropertyHandler FetchPropertyHandler()
        {
            MatchPropertyHandler matchPropertyHandler = new MatchPropertyHandler();
            MatchToNullablePropertyHandler matchToNullablePropertyHandler = new MatchToNullablePropertyHandler();
            MatchFromNullablePropertyHandler matchFromNullablePropertyHandler = new MatchFromNullablePropertyHandler();
            BooleanPropertyHandler booleanPropertyHandler = new BooleanPropertyHandler();
            EnumerationPropertyHandler enumerationPropertyHandler = new EnumerationPropertyHandler();
            ListPropertyHandler listPropertyHandler = new ListPropertyHandler();
            NumberPropertyHandler numberPropertyHandler = new NumberPropertyHandler();
            DefaultPropertyHandler defaultPropertyHandler = new DefaultPropertyHandler();

            // create the chain
            matchPropertyHandler.Successor = matchToNullablePropertyHandler;
            matchToNullablePropertyHandler.Successor = matchFromNullablePropertyHandler;
            matchFromNullablePropertyHandler.Successor = booleanPropertyHandler;
            booleanPropertyHandler.Successor = enumerationPropertyHandler;
            enumerationPropertyHandler.Successor = listPropertyHandler;
            listPropertyHandler.Successor = numberPropertyHandler;
            numberPropertyHandler.Successor = defaultPropertyHandler;

            // return the top
            return matchPropertyHandler;
        }
    }
}
